﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Net;
using System.Runtime.Serialization.Json;

namespace ServicioLugares
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "InformacionLugares" in code, svc and config file together.
    public class InformacionLugares : IInformacionLugares
    {
        public PlaceDetailReference GetDetalleLugar(string referencia)
        {
            string url = string.Format(
                "https://maps.googleapis.com/maps/api/place/details/json?reference={0}&sensor=false&key=AIzaSyDHKaKN1nH5LSR27DNbeZpUI9xtI2ztPjE",
                referencia
            );
            var request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(PlaceDetailReference));
            var res = (PlaceDetailReference)serializer.ReadObject(request.GetResponse().GetResponseStream());
            return res;
        }
    }
}
